﻿/**
*	Polygon
*	@author 	Liam O'Donnell 2008-04-01
**/

package com.spikything.pants3d.objects {
	
	import com.spikything.pants3d.objects.Group;
	import com.spikything.pants3d.objects.Sprite3D;
	import flash.display.Sprite;

	public class Polygon extends Sprite {
		
		public var points 		:Group; 	// The Group object associated with this polygon
		public var lineColour 	:Number;
		public var fillColour 	:Number;
		public var fillAlpha 	:Number;

		public function Polygon (points:Group, lineColour:Number=-1, fillColour:Number=-1, fillAlpha:Number=1) {
			this.points = points;
			this.lineColour = lineColour;
			this.fillColour = fillColour;
			this.fillAlpha = fillAlpha;
		}
		
		public function clear ():void {
			graphics.clear();
		}
		
		public function update ():void {
			clear();
			if (fillColour>-1) graphics.beginFill(fillColour, fillAlpha);
			if (lineColour>-1) graphics.lineStyle(0, lineColour);
			var firstPoint:Sprite3D = points.points[0] as Sprite3D; //points.sprites
			graphics.moveTo(firstPoint.x, firstPoint.y);
			var i:int;
			for (i = 1; i < points.points.length; i++) {
				var point:Sprite3D = points.points[i] as Sprite3D;
				graphics.lineTo(point.x, point.y);
			}
			graphics.lineTo(firstPoint.x, firstPoint.y);
			graphics.endFill();
			
		}

	}
	
}